package com.pm.megapinhata.client.view;

import com.google.gwt.user.client.ui.Label;
import com.pm.megapinhata.client.constants.ColorHexa;
import com.pm.megapinhata.client.constants.NavigationContext;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.events.MouseOutEvent;
import com.smartgwt.client.widgets.events.MouseOutHandler;
import com.smartgwt.client.widgets.events.MouseOverEvent;
import com.smartgwt.client.widgets.events.MouseOverHandler;
import com.smartgwt.client.widgets.layout.HLayout;

public class OpcaoMenuView extends HLayout {
	
	private String[] released;
	private final NavigationContext context;
	private boolean selectionFlag = false; 
	
	public OpcaoMenuView(final NavigationContext context, Label optionName, String img, String[] acess) {
		
		setWidth100();
		setHeight("25");
		setAlign(Alignment.LEFT);
		setMembersMargin(5);
		setBackgroundColor(ColorHexa.DEFAULT.getColor());
		
		this.context = context;
		this.released = acess;
				
		addMember(new Img(img, 16, 16));
		addMember(optionName);
		
		addMouseOverHandler(new MouseOverHandler() {
			
			public void onMouseOver(MouseOverEvent event) {
				if(!selectionFlag)
					setBackgroundColor(ColorHexa.LIGHT_BLUE.getColor());
			}
		});
		
		addMouseOutHandler(new MouseOutHandler() {
			
			public void onMouseOut(MouseOutEvent event) {
				if(!selectionFlag)
					setBackgroundColor(ColorHexa.DEFAULT.getColor());
			}
		});
		
	}

	public boolean checkGroup(String groupId){
		for (int i = 0; i < released.length; i++) {
			if(groupId.equals(released[i]))
				return true;
		}
		return false;
	}
	public NavigationContext getContext() {
		return context;
	}
	
	public void setSelection(boolean change){
		if(change == false){
			setBackgroundColor(ColorHexa.DEFAULT.getColor());
		}else{
			setBackgroundColor(ColorHexa.LIGHT_SKY_BLUE.getColor());
		}
		selectionFlag = change; 
	}
	
}
